package com.gbits.app.finance.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gbits.app.finance.domain.BusinessCashFlowSubjectMapper;
import com.gbits.app.finance.service.BusinessCashFlowSubjectMapperService;
import com.gbits.app.finance.service.DefaultAbstractService;

@Service("businessCashFlowSubjectMapperService")
@Transactional
public class BusinessCashFlowSubjectMapperImpl extends
		DefaultAbstractService<BusinessCashFlowSubjectMapper> implements
		BusinessCashFlowSubjectMapperService {

	public BusinessCashFlowSubjectMapper get(String orgCode, String subjectName) {
		String hql = " from " + BusinessCashFlowSubjectMapper.class.getName() + " e where e.orgCode=:orgCode and e.lastSubjectName=:lastSubjectName";
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("orgCode", orgCode);
		map.put("lastSubjectName", subjectName);
		List<BusinessCashFlowSubjectMapper> list = super.getBaseDao().findByNamesParameter(hql, map);
		
		if (null == list || list.isEmpty()) {
			throw new RuntimeException(String.format("未找到匹配的配制[现金流量表科目][%s,%s]", orgCode, subjectName));
		}
		
		if (list.size() == 1) {
			return list.get(0);
		} 
		
		throw new RuntimeException(String.format("找到多个匹配的配制[现金流量表科目][%s,%s]", orgCode, subjectName));
	}

}
